package com.mceil.mceilbase.activity;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.kongzue.dialogx.dialogs.InputDialog;
import com.kongzue.dialogx.dialogs.MessageDialog;
import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
import com.mceil.mceilbase.R;
import com.mceil.mceilbase.adapter.AddRecordsAdpter;
import com.mceil.mceilbase.bean.AddRecordsBean;
import com.mceil.mylibrary.annotation.ContentView;
import com.mceil.mylibrary.annotation.ViewInject;
import com.mceil.mylibrary.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import es.dmoral.toasty.Toasty;

@ContentView(R.layout.activity_add_records)
public class AddRecordsActivity extends BaseActivity {
    @ViewInject(R.id.toolbar)
    TitleBar toolBar;

    @ViewInject(R.id.recycler_view)
    RecyclerView recyclerView;

    @Override
    protected void initPreferences() {
        toolBar.setTitle("2023年12月12日");
        toolBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(TitleBar titleBar) {
                finish();
            }

            @Override
            public void onTitleClick(TitleBar titleBar) {
                OnTitleBarListener.super.onTitleClick(titleBar);
            }

            @Override
            public void onRightClick(TitleBar titleBar) {
                OnTitleBarListener.super.onRightClick(titleBar);
            }
        });
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        List<AddRecordsBean> mDatas = new ArrayList<>();
        for (int i = 0; i < 40; i++) {
            if (i%2==0) {
                mDatas.add(new AddRecordsBean(1,"郑子阳"));
            }else{
                mDatas.add(new AddRecordsBean(2,"张子涵"));
            }
        }
        initList(mDatas);
    }

    private void initList(List<AddRecordsBean> mDatas) {
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
        AddRecordsAdpter adadpter = new AddRecordsAdpter(R.layout.item_add_records, mDatas);
        recyclerView.setAdapter(adadpter);
        adadpter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                showAddDialog();
            }
        });
    }

    private void showAddDialog() {
//        MessageDialog.show("成功提交", "您的意见我们已收到，感谢您对礼记簿子的支持和帮助！"
//                , "确定", "");

        new InputDialog("张子昂", "", "提交", "取消")
                .setTitleIcon(getDrawable(R.drawable.icon_boy))
                .setOkButtonClickListener(new OnDialogButtonClickListener<MessageDialog>() {
                    @Override
                    public boolean onClick(MessageDialog dialog, View v) {
                        Toasty.success(mContext, "成功提交");
                        return false;
                    }
                })
                .show();
    }
}
